var ctx=window.daijia.ctx;
var year=window.daijia.year;
var companyId="";
if($("#companyId").length>0){
	companyId=$("#companyId").val();
}
$(document).ready(function(){
	//初始化
	loadData();
	$("#search_button").click(function(){
		loadData();
		companyId=$("#companyId").val();
	});

	//导出。。。。。。。。
	//导出数量
	$("#allAmount").click(function(){
		if($(this).is(':checked')){
			$("#amounts").attr("disabled",true);
		}
		else{
			$("#amounts").attr("disabled",false);
		}
	});
	
	//开始导出
	$("#export_button").click(function(){
		
		if(!$("#allAmount").is(':checked')){
			var amounts=$("#amounts").val();
			if(amounts==""){
				$.scojs_message("请输入导出数量", $.scojs_message.TYPE_ERROR);
				return false;
			}
			else if(amounts<=0){
				$.scojs_message("导出数量最少为1条", $.scojs_message.TYPE_ERROR);
				return false;
			}
		}
		
		window.location=ctx+"/chart/exportTableNewMemberMonth?"+$("#ExportForm").serialize();
	});
	


function loadData(){
	
	if($('#loadblacklayer').length==0){
		var dw = $(".table").width();
		var dh = $(".table").height();
		var backlayer ="<div id='loadblacklayer'><div style='margin-top:"+(dh/2)+"px;margin-left:"+(dw/2)+"px;'><img src='"+ctx+"/assets/css/images/loading.gif' /></div></div>"
		$(".table tbody").append(backlayer);
		$('#loadblacklayer').css({"z-index":"9","background":"#000","opacity":"0.5","position":'absolute',"top":0,"width":dw,"height":dh});
	}
	
	var newcontent = '';
	$.ajax({
		
        url : ctx+'/chart/tableNewMemberMonthData',
        type:'GET',
        async:true,
        dataType : 'json',
        data : {
        
        	"year":$("#year").val(),
        	"companyId":$("#companyId").val()
        },
        success : function(result){
        	if(result.length>0){
        		
        newcontent+="<tbody style='display:none;'>";		
        		$(result).each(function(index,data){
        			
	    newcontent+="<tr>"+
						"<td>"+data[0]+"</td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=1&companyId="+companyId+"' target='_blank'>"+(data[1]==null||data[1]==0?"-":data[1])+"</a></td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=2&companyId="+companyId+"' target='_blank'>"+(data[2]==null||data[2]==0?"-":data[2])+"</a></td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=3&companyId="+companyId+"' target='_blank'>"+(data[3]==null||data[3]==0?"-":data[3])+"</a></td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=4&companyId="+companyId+"' target='_blank'>"+(data[4]==null||data[4]==0?"-":data[4])+"</a></td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=5&companyId="+companyId+"' target='_blank'>"+(data[5]==null||data[5]==0?"-":data[5])+"</a></td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=6&companyId="+companyId+"' target='_blank'>"+(data[6]==null||data[6]==0?"-":data[6])+"</a></td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=7&companyId="+companyId+"' target='_blank'>"+(data[7]==null||data[7]==0?"-":data[7])+"</a></td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=8&companyId="+companyId+"' target='_blank'>"+(data[8]==null||data[8]==0?"-":data[9])+"</a></td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=9&companyId="+companyId+"' target='_blank'>"+(data[9]==null||data[9]==0?"-":data[9])+"</a></td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=10&companyId="+companyId+"' target='_blank'>"+(data[10]==null||data[10]==0?"-":data[10])+"</a></td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=11&companyId="+companyId+"' target='_blank'>"+(data[11]==null||data[11]==0?"-":data[11])+"</a></td>"+
						"<td><a href='"+ctx+"/chart/tableNewMemberMonthDetail?fromSource="+data[0]+"&year="+year+"&month=12&companyId="+companyId+"' target='_blank'>"+(data[12]==null||data[12]==0?"-":data[12])+"</a></td>"+
					"</tr>";
        		});
        		
       newcontent+="</tbody>";		
        	}
        	$('#loadblacklayer').remove();
        	$(".table tbody").remove();
        	$(".table").append(newcontent);
        	$(".table tbody").show(300);
    	}
	});
	
	//return newTotalElements;
}

});
	

